﻿using System;
using System.Collections.Generic;
using System.Text;

namespace 西南财经大学学术讲座信息获取小工具
{
    public class XueShu
    {
        private string url;

        public string Url
        {
            get { return url; }
            set { url = value; }
        }
        private string title;

        public string Title
        {
            get { return title; }
            set { title = value; }
        }
        private string time;

        public string Time
        {
            get { return time; }
            set { time = value; }
        }
        private string speaker;

        public string Speaker
        {
            get { return speaker; }
            set { speaker = value; }
        }
        private string location;

        public string Location
        {
            get { return location; }
            set { location = value; }
        }
        public static List<XueShu> GetXueShu()
        {
            List<XueShu> xs = new List<XueShu>();
            string temp = WebHelper.GetHtmlCodeByWebClient("http://www.swufe.edu.cn/newsjz.html", "gbk");
            temp = WordHelper.CutWordByKeyword(temp, "<tr bgcolor=\"#CCCCCC\" style=\"color:#0068bh;\" align=\"center\">", "<SCRIPT LANGUAGE=\"JavaScript\">");
            string[] urls = WordHelper.GetWords(temp, "<a href=\"", "\"   target=\"_blank\">");
            int maxNum = urls.Length > 15 ? 15 : urls.Length;
            for (int i = 0; i < maxNum; i++)
            {
                xs.Add(new XueShu("http://www.swufe.edu.cn/" + urls[i]));
            }
            return xs;
        }

        public XueShu(string url)
        {
            this.Url = url;
            string temp = WebHelper.GetHtmlCodeByWebClient(url, "gb2312");
            temp = WordHelper.CutWordByKeyword(temp, "<p align=left  style=\"line-height: 150%;font-size=14px\" id=showcontent>", "</pre>");
            temp = temp.Replace("题  目：","主  题：");
            temp=temp.Replace("主    题：","主  题：");
            temp = temp.Replace("主  题:", "主  题：");
            this.Title = WordHelper.CutWordByKeyword(temp, "主  题：", "\n").Trim();
            temp = temp.Replace("主讲人:", "主讲人：");
            temp = temp.Replace("主持人：", "主讲人：");
            temp = temp.Replace("主 讲 人：", "主讲人：");
            this.Speaker = WordHelper.CutWordByKeyword(temp, "主讲人：", "\n").Trim();
            temp = temp.Replace("时 间：", "时  间：");
            temp = temp.Replace("时  间：", "时  间：");
            temp = temp.Replace("时  间:", "时  间：");
            temp = temp.Replace("时    间：", "时  间：");
            this.Time = WordHelper.CutWordByKeyword(temp, "时  间：", "\n").Trim();
            temp = temp.Replace("地  点: ", "地  点：");
            temp = temp.Replace("地    点：", "地  点：");
            this.Location = WordHelper.CutWordByKeyword(temp, "地  点：", "\n").Trim();
        }
    }
}
